<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>vue 组件 非父子组件间传值(BUs/观察者模式)</title>
    <script src="./vue.js"></script>
   
</head>
<body>
    <div id="app">
        <counter content="dell"></counter>
        <counter content="Hi"></counter>
    </div>
    <script>
        Vue.prototype.bus = new Vue()//Vue实例挂载bus属性 属性值Vue实例
        Vue.component('counter',{
            data: function(){
                return {
                    selfContent: this.content
                }
            },
            props: {
                content: String
            },
            template: `<div @click="handles">{{selfContent}}</div>`,
            methods: {
                handles: function(){
                    this.bus.$emit("change",this.selfContent)//推送事件change 被观察者
                }
            },
            mounted:function(){ //生命周期 钩子监听  观察者
                var _this = this
                this.bus.$on('change',function(msg){
                    _this.selfContent = msg
                })
            }

        })
        var vm = new Vue({
            el: '#app',
            data: {
              total: 0
            },
            //方法
            methods:{
                
            },
            //组件
            components: {
                
            },
            //计算属性
            computed:{
               
            }


        })
    </script>
</body>
</html>